#include "Font.h"

namespace Y{

Font::Font( const OString& str )
{
//	fontTexture.load(OString(str) + "_1024.png");
//	fontTexture.toGLTexture(true,false);
	fontTexture = new Texture(OString(str) + "_1024.png",false,true);
	
	for ( int i = 0; i < 100; ++i ){
		float row = (float) (i / 10);
		float col = (float) (i % 10);
		
		Vertex4f& a = ctc[i];
		a[0] = col / 10.0f;
		a[1] = row / 10.0f;
		int px = a[0] * 1024;
		int py = a[1] * 1024;
		bool st = true;
		for ( int i = 0; i < 102; ++i ){
			for ( int j = 0; j < 102; ++j ){
				if ( fontTexture->acc(px + i,py + j,3) != 0 ){
					a[0] += 0.1 * ((float)i / 102.0f);
					st = false;
					break;
				}
			}
			if ( !st ){ break; }
		}
		
		st = true;
		for ( int i = 101; i >= 0; --i ){
			for ( int j = 0; j < 102; ++j ){
				if ( fontTexture->acc(px + i,py + j,3) != 0 ){
					a[2] = (((float) col / 10.0f) + 0.1 * ((float)i / 102.0f)) - a[0];
					a[3] = 0.1;
					st = false;
					break;
				}
			}
			if ( !st ){break;}
		}
	}
}

Vertex4f& Font::characterTexCoord ( char c ){
	int i = (int) (c - ' ');
	return ctc[i];
}

}